package com.tao.controller.webpageController;

import com.tao.pojo.dto.ShoppingCartDto;
import com.tao.result.Result;
import com.tao.service.ShoppingCartService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@Slf4j
@RequestMapping("/webPage/shoppingCart")
public class ShoppingCartController {
    @Autowired
    ShoppingCartService shoppingCartService;

    @GetMapping("/get")
    public Result selectAllShoppingCart(){
       return Result.success(shoppingCartService.selectShoppingCart());
    }

    @PostMapping("/add")
    public Result addShoppingCart(@RequestBody ShoppingCartDto shoppingCartDto){
        shoppingCartService.addShoppingCart(shoppingCartDto);
        return Result.success();
    }

    @PostMapping("/sub")
    public Result subShoppingCart(@RequestBody ShoppingCartDto shoppingCartDto){
        shoppingCartService.subShoppingCart(shoppingCartDto);
        return Result.success();
    }

    @DeleteMapping("/clean")
    public Result cleanShoppingCart(){
        shoppingCartService.cleanShoppingCart();
        return Result.success();
    }
}
